var root =''; var questions; var questionsList=[]; var localStg = "LOC_STG_ENC"; var homoclave = ""; var sending = false; function loadModal() { if(document.getElementsByName("homoclave") !== null && document.getElementsByName("homoclave").length >0){ homoclave = document.getElementsByName("homoclave")[0].value; } //window.document.body.innerHTML += '
'; var elemDiv = document.createElement('div'); elemDiv.setAttribute("id","modEncuestaSatisfaccion"); elemDiv.setAttribute("class","modal fade"); elemDiv.setAttribute("name","modEncuestaSatisfaccion"); document.body.appendChild(elemDiv); $('#modEncuestaSatisfaccion').on('hidden.bs.modal', function() { saveInformation(); }); } function getAnswer(answerView) { var selectedList = []; var nodeList = document.getElementsByName(answerView); for (var i = 0; i < nodeList.length; i++) { if(nodeList[i].type === 'radio' && nodeList[i].checked) { selectedList.push(nodeList[i].value); } else if(nodeList[i].type === 'checkbox' && nodeList[i].checked) { selectedList.push(nodeList[i].value); } else if(nodeList[i].type === 'input') { selectedList.push(nodeList[i].value); } else if(nodeList[i].type === 'submit') { for(var index = 0 ; index < nodeList[i].classList.length; index++) { if(nodeList[i].classList[index] === 'active') { selectedList.push(nodeList[i].value); } } } } return selectedList.length > 0 ? selectedList : null; } function goToView(questionView,answerView) { var answer; answer = getAnswer(answerView); if(questionView === "Q_A") { if(answer.length >0 && answer[0] === '1') { showQuestionView("Q_R"); hideQuestionView("Q_B"); removeListElement("Q_B"); clearSelection("A_B"); hideQuestionView("Q_C"); removeListElement("Q_C"); clearSelection("A_C"); hideQuestionView("Q_D"); removeListElement("Q_D"); clearSelection("A_D"); hideQuestionView("S_A"); } else { hideQuestionView("Q_R"); removeListElement("Q_R"); clearSelection("A_R"); if(answer.length > 0 && answer[0] === '2') { hideQuestionView("Q_B"); removeListElement("Q_B"); clearSelection("A_B"); hideQuestionView("Q_C"); removeListElement("Q_C"); clearSelection("A_C"); showQuestionView("Q_D"); showQuestionView("S_A"); } else { hideQuestionView("Q_B"); removeListElement("Q_B"); clearSelection("A_B"); hideQuestionView("Q_C"); removeListElement("Q_C"); clearSelection("A_C"); showQuestionView("Q_D"); showQuestionView("S_A"); } } } else { if(questionView === "Q_R") { if(answer.length >0 && answer[0] === '1') { showQuestionView("Q_B"); showQuestionView("Q_C"); } else{ hideQuestionView("Q_B"); removeListElement("Q_B"); clearSelection("A_B"); hideQuestionView("Q_C"); removeListElement("Q_C"); clearSelection("A_C"); } } } addListElement(questionView,answer); setLocalStorage(localStg, parseToJSON(questionsList) ); } function removeListElement(questionView) { for (var i = 0; i < questionsList.length; i++) { if(questionsList[i].question === questionView) { questionsList.splice(i,1); } } } function addListElement(questionView, answer) { var question = {}; question.question = questionView; question.answer = answer; var exist = false; for (var i = 0; i < questionsList.length; i++) { if(questionsList[i].question === questionView) { questionsList[i] = question; exist = true; } } if(exist === false) { questionsList.push(question); } } function clearSelection(answerView){ var elements = document.getElementsByName(answerView); for (var i = 0; i < elements.length; i++) { if(elements[i].type === 'radio' || elements[i].type === 'checkbox') { elements[i].checked = false; } if(elements[i].type === 'input') { elements[i].value = ""; } } } function hideQuestionView(questionView) { document.getElementById(questionView).style.display = 'none'; } function showQuestionView(questionView) { document.getElementById(questionView).style.display = 'block'; } function selectRadio(radio) { document.getElementById(radio).checked = true; } function selectButton(button,group) { var buttons_group = document.getElementsByName(group); for(index = 0; index < buttons_group.length; index++) { if(document.getElementsByName(group)[index].id===button) { document.getElementsByName(group)[index].classList.add("active"); var test = document.getElementsByName(group)[index]; var replace = $(test).find('img').attr('src'); reply = replace.split('.')[3].split('/')[3].split('-')[2]; if(reply.toString() === 'good') { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satifation-good-2.svg'); }else if(reply.toString() === 'regular') { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satifation-regular-2.svg'); }else if(reply.toString() === 'bad') { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satifation-bad-2.svg'); } //console.log('replace -> ' + replace.split('.')[3].split('/')[3].split('-')[2] ) } else { for(var indexActive= 0 ; indexActive < document.getElementsByName(group)[index].classList.length;indexActive++){ if(document.getElementsByName(group)[index].classList[indexActive]==='active') { document.getElementsByName(group)[index].classList.remove("active"); var test = document.getElementsByName(group)[index]; var replace = $(test).find('img').attr('src'); reply = replace.split('.')[3].split('/')[3].split('-')[2]; if(reply.toString() === 'good') { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satisfation-good.svg'); } else if ( reply.toString() === 'regular' ) { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satisfation-regular.svg'); } else if ( reply.toString() === 'bad' ) { $(test).find('img').attr('src', 'https://framework-gb.cdn.gob.mx/assets/images/ico-satisfation-bad.svg'); } } } } } } function selectCheckbox(chk){ if(document.getElementById(chk).checked === true) { document.getElementById(chk).checked = false; } else { document.getElementById(chk).checked = true; } } function loadQuestions(){ var elements = []; $.ajaxSetup({ async: false }); $.getJSON('https://framework-gb.cdn.gob.mx/data/encuesta_v1.0/encuesta.json', function(jd) { //$.getJSON('http://localhost:8888/qa/encuesta.json', function(jd) { elements=[].concat(jd); }).success(function() { // TODO }).error(function(error) { // TODO manejo de errores }); $.ajaxSetup({ async: true }); this.questions = elements; var container = ""; for(index = 0; index < this.questions.length; index++) { if(this.questions[index].visible) { container+="